# -*- coding: utf-8 -*-

from gtk import *
from includes import *
from os.path import *

class PhotoError(Exception):
	def __init__(self, value):
		self.value = value
	def __str__(self):
		return self.value

class Photo:
	
	def __init__(self, data):
		self.filepath = normpath(data[0])
		infos = data[1]
		self.type = infos[0]['name']
		self.x = 0
		self.y = 0
		self.width = infos[1]
		self.height = infos[2]
		self.nb_copy = 1
		self.name = basename(self.filepath)
		self.pixbuf = gdk.pixbuf_new_from_file(self.filepath)
		if self.pixbuf.get_width() > self.pixbuf.get_height():
			width = THUMB_SIZE
			height = int((float(self.pixbuf.get_height()) / float(self.pixbuf.get_width())) * THUMB_SIZE)
		else:
			height = THUMB_SIZE
			width = int((float(self.pixbuf.get_width()) / float(self.pixbuf.get_height())) * THUMB_SIZE)
		if width < 1 or height < 1:
			raise PhotoError("Image trop mince en largeur ou hauteur")
		self.thumb = self.pixbuf.scale_simple(width, height, gdk.INTERP_HYPER)
		
		
